﻿<cfsilent>
	<cfscript>
	
		event.setArg("pageTitle", "教师门户 - 考试任务");
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");

		teacherId = sessionAdvice.getAutherUserID();
		
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		termId = event.getArg("TermID");
			
		/* 读取学期信息 */
		sql = " SELECT 
					term_id, academic_year, academic_term 
				FROM 
					t_term 
				WHERE 
					term_id = :termId 
				ORDER BY 
					term_id";
					
		queryObj = new query( datasource=application.dnsSlave );
		
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		
		rs_term = queryObj.execute( sql=sql ).getResult();
		
		/* 学院尚未安排考试课程设置 */
		sql = "SELECT 
				   t_course.course_name, 
				  t_course.course_credit, 
				 (SELECT COUNT(*) FROM t_student_course a WHERE a.task_id = t_task.tsk_id) countEX,
				  t_course.cid ,t_task.tsk_id ,
				  (SELECT t_new_examtask.is_arranged from t_new_examtask where t_new_examtask.task_id = t_task.tsk_id ) isArranged  
				  
			  FROM 
				  t_task  
				  INNER JOIN t_course ON t_course.cid = t_task.cid 
			  WHERE 
				  t_task.term_id = :termId 
				  AND 
				  t_task.tch_id = :teacherId 
				  AND NOT EXISTs(
				  	SELECT 1 from t_new_examtask where t_new_examtask.task_id = t_task.tsk_id and t_new_examtask.is_arranged = '3'
				  )
			  ORDER BY 
				isArranged, t_course.course_name";
					
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
		
		rs_courseToDo = queryObj.execute( sql=sql ).getResult();
		
		/* 学院尚未安排考试课程设置-不参加考试 */
		  sql = "SELECT 
				  t_examplan.task_type, t_course.course_name, 
				  t_course.course_credit, 
				 (SELECT COUNT(*) FROM t_student_course a WHERE a.task_id = t_examplan.task_id) countEX,
				  t_course.cid 
			  FROM 
				  t_examplan 
				  INNER JOIN t_course ON t_course.cid = t_examplan.cid 
				  INNER JOIN t_task ON t_task.tsk_id = t_examplan.task_id 
			  WHERE 
				  t_examplan.term_id = :termId 
				  AND 
				  t_examplan.is_arrange = 'N' 
				  AND 
				  t_task.tch_id = :teacherId 
			  ORDER BY 
				  t_examplan.task_type, t_course.course_name ";
				  
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
		
		rs_courseNo = queryObj.execute( sql=sql ).getResult();
		
		/*期末考试任务*/
		sql = "select a.*, c.tch_name, d.course_name,d.course_credit,e.classroom,b.task_chooesd 
				from t_new_examtask a 
				INNER JOIN t_task b on b.tsk_id = a.task_id 
				INNER JOIN t_teacher c ON c.tch_id = b.tch_id 
				INNER JOIN t_course d ON d.cid = b.cid 
				INNER JOIN t_classroom e ON e.cr_id = a.cr_id 
				where a.is_arranged = '3' 
			     AND b.term_id = :termId 
				AND b.tch_id = :teacherId 
				order by a.date_exam, a.time_start"; 
		
		queryObj = new query( datasource=application.dnsSlave );
		
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
		
		rs_examTask = queryObj.execute( sql=sql ).getResult();
		
		
		/*期末提前考试任务*/
		sql = "select a.*, d.course_name,d.course_credit,e.classroom,b.task_chooesd, 
					(select count(*) from t_new_examadvice_student s where s.task_id = a.task_id) count 
				from t_new_examtaskAdvice a 
				INNER JOIN t_task b on b.tsk_id = a.task_id 
				INNER JOIN t_teacher c ON c.tch_id = b.tch_id 
				INNER JOIN t_course d ON d.cid = b.cid 
				INNER JOIN t_classroom e ON e.cr_id = a.cr_id 
				where a.is_arranged = '3' 
			     AND b.term_id = :termId 
				AND b.tch_id = :teacherId 
				order by e.classroom, a.date_exam, a.time_start"; 
		
		queryObj = new query( datasource=application.dnsSlave );
		
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
		
		rs_examTaskAdvice = queryObj.execute( sql=sql ).getResult();
		
		/*期中考试任务*/
		sql = "SELECT 
					t_examtask.task_exid,
					t_course.course_name, 
					t_campus.campus_name,
					t_examtask.wid, 
					t_examtask.examer_sum, 
					t_institute.institute_short, 
					t_examtask.wdidx,
					t_examtask.cellidx, 
					(SELECT COUNT(*) FROM t_clsroom_forexam WHERE t_clsroom_forexam.task_exid = t_examtask.task_exid) countCls      
				FROM 
					t_examtask 
					INNER JOIN t_course ON t_course.cid = t_examtask.cid 
					INNER JOIN t_campus ON t_campus.campus_id = t_examtask.campus_id 
					INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
					INNER JOIN mv_running_task ON mv_running_task.cid = t_course.cid 
				WHERE 
					t_examtask.term_id = :termId 
					AND 
					t_examtask.task_prog = '3' 
					AND 
					t_examtask.exam_type = 'M' 
					AND (
						mv_running_task.tch_id = :teacherId 
						OR 
						mv_running_task.tch_id_sec = :teacherId 
						OR 
						mv_running_task.tch_id_ace = :teacherId 
					)
				
				ORDER BY 
					t_examtask.wid, t_institute.institute_short, t_course.course_name "; 
		
		queryObj = new query( datasource=application.dnsSlave );
		
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
		
		rs_midExamTask = queryObj.execute( sql=sql ).getResult();
	
		/* 判断当前显示内容 */
		currentTab = event.getArg("TabID", "labFinExamTask");
		
		if ( rs_midExamTask.recordCount ){
			currentTab = event.getArg("TabID", "labMidExamTask");
		} 
		
		passArgs = structNew();
		targetArgs = structNew();
	
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">教学活动</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 program"></i>考试安排
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<div class="UItab">
					<div class="tabLables">
						<!---<span <cfif currentTab eq "labMidExamTask">class="active"</cfif> id="labFinExamTask" tabTarget="MidExamTask">期中考试</span>--->
                        		<span <cfif currentTab eq "labFinExamTask">class="active"</cfif> id="labMidExamTask" tabTarget="FinExamTask">期末考试</span>
                              <span <cfif currentTab eq "labExamTaskCreate">class="active"</cfif> id="labExamTaskCreate" tabTarget="ToArrange">尚未安排</span>
                              <cfif rs_courseNo.recordCount>
							<span <cfif currentTab eq "labNoArrange">class="active"</cfif> id="labNoArrange" tabTarget="NoArrange">不考试课程</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="MidExamTask" class="tabContent">
                
                              
                         <div class="noticeBlock">
                             <h3>期中考试安排</h3>
                             <p>
                                 <span class="img icon16x16 message"></span>
                                 <cfif rs_midExamTask.recordCount>
                                     在<em><cfoutput>#rs_term.academic_year#</cfoutput>-<cfoutput>#rs_term.academic_term#</cfoutput></em>学期您承担的教学任务的期中考试安排如下.</p>
                                   <cfelse>
                                        在<em><cfoutput>#rs_term.academic_year#</cfoutput>-<cfoutput>#rs_term.academic_term#</cfoutput></em>学期您承担的教学任务没有期中考试安排.</p>
                                 </cfif>
                             <hr/>
                         </div>
       
				
					
					<cfif rs_midExamTask.recordCount>
                    	
                        <cfset row = 0 />
					
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="25"></td>
									<td width="60">任课单位</td>
									<td>课程</td>
									<td width="60">考试校区</td>
									<td width="30">周次</td>
									<td width="80">时间</td>
									<td width="40">人数</td>
									<td width="40">考场</td>
									<td width="25"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_midExamTask" >
                                	<cfset row ++ />
									<cfset structInsert(passArgs, "EXID", rs_midExamTask.task_exid, true) />
									<cfset structInsert(passArgs, "ExamType", "M", true) />
									<tr class="editRows">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_midExamTask.institute_short#</cfoutput></td>
										<td><cfoutput>#rs_midExamTask.course_name#</cfoutput></td>
										<td><cfoutput>#rs_midExamTask.campus_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_midExamTask.wid#</cfoutput></span></td>
										<td><cfoutput>#mathAdvice.convertWeekDayToChinese(rs_midExamTask.wdidx)#</cfoutput><cfoutput>#mathAdvice.convertExamIdxToChinese(rs_midExamTask.cellidx)#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_midExamTask.examer_sum#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#rs_midExamTask.countCls#</cfoutput></span></td>
										<td><a title="查看课程考试详细安排" class="stat details" href="<cfoutput>#buildURL('examTaskPrint', passArgs)#</cfoutput>"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
						
						<cfelse>
						
						<div class="systemNotice">
							<p>目前, 您承担的教学任务尚未发布考试安排</p>
						</div>
						
					</cfif>
				</div>
                
                <div id="FinExamTask" class="tabContent">
                
                    
                    <div class="noticeBlock">
                        <h3>期末考试安排</h3>
                        <p>
                            <span class="img icon16x16 message"></span>
                            <cfif rs_examTask.recordCount >
                                在<em><cfoutput>#rs_term.academic_year#</cfoutput>-<cfoutput>#rs_term.academic_term#</cfoutput></em>学期您承担的教学任务的期末考试安排如下.</p>
                              <cfelse>
                              	在<em><cfoutput>#rs_term.academic_year#</cfoutput>-<cfoutput>#rs_term.academic_term#</cfoutput></em>学期您承担的教学任务没有期末考试安排.</p>
                            </cfif>
                        <hr/>
                    </div>
       
				<cfif rs_examTask.recordCount or rs_examTaskAdvice.recordCount>
                    	
                        <cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="25"></td>
									<td>课程</td>
									<td >考场</td>
									<td>考试日期</td>
									<td>考试时间</td>
                                             <td>类型</td>
									<td >人数</td>
                                             <td >学分</td>
                                             <td width="25"></td>
									
								</tr>
							</thead>
							<tbody>
                                    <cfloop query="rs_examTaskAdvice" >
                                       <cfset row ++ />
									<cfset structInsert(passArgs, "taskId", rs_examTaskAdvice.task_id, true) />
                                             <cfset structInsert(passArgs, "ExamType", "F", true) />
                                             <tr class="editRows">
                                                  <td class="index"><cfoutput>#row#</cfoutput></td>
                                                  <td><cfoutput>#rs_examTaskAdvice.course_name#</cfoutput></td>
                                                  
                                                  <td><cfoutput>#rs_examTaskAdvice.classroom#</cfoutput></td>
                                                  <td><cfoutput>#datetimeAdvice.formatDateString( rs_examTaskAdvice.date_exam )#</cfoutput></td>
                                                  <td><cfoutput>#datetimeAdvice.formatTimeString(rs_examTaskAdvice.time_start, 'HH:MI')#</cfoutput> ~ <cfoutput>#datetimeAdvice.formatTimeString(rs_examTaskAdvice.time_end, 'HH:MI')#</cfoutput></td>
                                                   <td><span style="color:#F0F">提前考试</span></td>
                                                  <td><span class="numeric"><cfoutput>#rs_examTaskAdvice.count#</cfoutput> / <cfoutput>#rs_examTaskAdvice.task_chooesd#</cfoutput></span></td>
                                                  
                                                <td><span class="numeric"><cfoutput>#rs_examTaskAdvice.course_credit#</cfoutput></span></td>
                                                  <td>
                                                  <a title="删除课程考试安排" onclick="return checked();" class="stat delete" href="<cfoutput>#buildURL('examAdviceTaskDelete', passArgs)#</cfoutput>"></a>
                                                  </td>
                                             <!---<td><a title="查看课程考试详细安排" class="stat details" href="<cfoutput>#buildURL('examTaskPrint', passArgs)#</cfoutput>"></a></td>--->
                                             </tr>
                                        </cfloop>
                                          <cfset row = 0 />
                                          
                                      <cfloop query="rs_examTask" >
                                         <cfset row ++ />
                                                   <cfset structInsert(passArgs, "taskId", rs_examTask.task_id, true) />
                                                   <cfset structInsert(passArgs, "ExamType", "F", true) />
                                                   <tr class="editRows">
                                                        <td class="index"><cfoutput>#row#</cfoutput></td>
                                                        <td><cfoutput>#rs_examTask.course_name#</cfoutput></td>
                                                        <td><cfoutput>#rs_examTask.classroom#</cfoutput></td>
                                                        <td><cfoutput>#datetimeAdvice.formatDateString( rs_examTask.date_exam )#</cfoutput></td>
                                                        <td><cfoutput>#datetimeAdvice.formatTimeString(rs_examTask.time_start, 'HH:MI')#</cfoutput> ~ <cfoutput>#datetimeAdvice.formatTimeString(rs_examTask.time_end, 'HH:MI')#</cfoutput></td>
                                                        <td>正常考试</td>
                                                        <td><span class="numeric"><cfoutput>#rs_examTask.task_chooesd#</cfoutput></span></td>
                                                      <td><span class="numeric"><cfoutput>#rs_examTask.course_credit#</cfoutput></span></td>
                                                        <td><a title="删除课程考试安排" onclick="return checked();" class="stat delete" href="<cfoutput>#buildURL('examTaskDelete', passArgs)#</cfoutput>"></a></td>
                                                   <!---<td><a title="查看课程考试详细安排" class="stat details" href="<cfoutput>#buildURL('examTaskPrint', passArgs)#</cfoutput>"></a></td>--->
                                                   </tr>
								</cfloop>
							</tbody>
						</table>
						
						<cfelse>
						
						<div class="systemNotice">
							<p>目前, 您承担的教学任务尚未发布考试安排</p>
						</div>
						
					</cfif>
					
				</div>
                    
                    <div id="ToArrange" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
						</div>
						<h3>等待安排考试周次</h3>
						<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 有<em><cfoutput>#rs_courseToDo.recordCount#</cfoutput></em>门课程等待安排考试时间</p>
						<hr/>
					</div>
					
					<cfif rs_courseToDo.recordCount>
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<!---<td width="18"></td>
									<td width="18"></td>--->
									<td>课程</td>
                                             <td>状态</td>
									<td >人数</td>
									<td >学分</td>
									<td width="18"></td>
                                             <td width="18"></td>
								</tr>
							</thead>
							<tbody>
								<cfloop query="rs_courseToDo">
									<cfset row++ />
									<cfset structInsert(targetArgs, "CID", rs_courseToDo.cid, true) />
									<cfset structInsert(targetArgs, "TT", "p", true) />
									<cfset structInsert(targetArgs, "taskId", rs_courseToDo.tsk_id, true) />
                                             
									<tr class="editRows">
										<!---<td><a title="该门课程不考试" href="<cfoutput>#buildURL('examCourseRemoveDo', passArgs)#</cfoutput>" class="stat remove"></a></td>--->
										<!---<td class="index"><cfoutput>#row#</cfoutput></td>--->
										<td><cfoutput>#rs_courseToDo.course_name#</cfoutput></td>
                                                  <td><cfif rs_courseToDo.isArranged eq '1' or rs_courseToDo.isArranged eq '2'>
                                                  		<font color="red">部分安排</font>
                                                        </cfif></td>
                                                  
										<td align="center"><span class="numeric"><cfoutput>#rs_courseToDo.countEx#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#numberFormat(rs_courseToDo.course_credit, "_.__")#</cfoutput></span></td>
                                                    <td><cfif rs_courseToDo.isArranged eq '1' or rs_courseToDo.isArranged eq '2'><a title="删除课程考试安排" onclick="return checked();" class="stat delete" href="<cfoutput>#buildURL('examTaskDelete', targetArgs)#</cfoutput>"></a></cfif></td>
										<td><a title="安排课程考试时间与地点" href="<cfoutput>#buildURL('examByCourse', targetArgs)#</cfoutput>" class="stat edit"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
						
					</cfif>
					
					
				</div>
                    
                    <cfif rs_courseNo.recordCount >
					
					<div id="NoArrange" class="tabContent">
						
						<div class="noticeBlock">
							<h3>不安排考试</h3>
							<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 有<em><cfoutput>#rs_courseNo.recordCount#</cfoutput></em>门课程已标注为不需要安排考试时间</p>
							<hr/>
						</div>
						
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td>开课类别</td>
									<td>课程</td>
									<td width="50">教学班</td>
									<td width="30">学分</td>
								</tr>
							</thead>
							<tbody>
								 <cfloop query="rs_courseNo">
									<cfset row++ />
									
									<cfset structInsert(passArgs, "CourseID", rs_courseNo.cid, true) />
									<cfset structInsert(passArgs, "TaskType", rs_courseNo.task_type, true) />

									<tr class="editRows">
										<!---<td class="index"><cfoutput>#row#</cfoutput></td>--->
										<td><a title="恢复该门课程考试安排" href="<cfoutput>#buildURL('examCourseRestoreDo', passArgs)#</cfoutput>" class="stat restore"></a></td>
										<td><cfoutput>#dictAdvice.getTaskType(rs_courseNo.task_type)#</cfoutput></td>
										<td><cfoutput>#rs_courseNo.course_name#</cfoutput></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_courseNo.countEx#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#numberFormat(rs_courseNo.course_credit, "_.__")#</cfoutput></span></td>
									</tr>
								</cfloop>
							</tbody>
						</table>

					</div>
					
				</cfif>
                    
                    
                      <script language="javascript" type="text/javascript">
				
                    	function checked(){
						var msg = "您真的确定要删除吗？\n\n请确认！"; 
						if (confirm(msg)==true){ 
							return true; 
						}else{ 
							return false; 
						} 
					}
                    
                    </script>
                    
             </div>
		</li>
	</ul>
</div>

